﻿Imports Oracle.DataAccess.Client
Imports lbGlobalcom
Public Class fSaldosProductos
    Dim daPrepack As dsConsultasGlobalTableAdapters.GLO_LISTAPREPACKTableAdapter
    ''Private Sub btnBuscaProducto_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
    ''    Try
    ''        Dim flPro As New fListaProductos
    ''        If flPro.ShowDialog = Windows.Forms.DialogResult.OK Then
    ''            txtProducto.Text = flPro.idArticulo
    ''            'lbDescripcionProducto.Text = flPro.pDescrip
    ''        End If
    ''    Catch ex As Exception
    ''        MessageBox.Show(ex.Message)
    ''        lbGlobalcom.cError.SalvaError(ex, "Henry")
    ''    End Try
    ''End Sub

    'Private Sub btnConsultar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
    '    Try
    '        DsInventarios.INV_DETALLEINVENTARIOS.Rows.Clear()
    '        DsInventarios.INV_INVENTARIOS.Rows.Clear()
    '        Dim cInv As New cConsultaSaldosInventario(DsInventarios, Me.txtProducto.Text, Me.txtBodega.Text)
    '        cInv.consultarSaldo()
    '        INV_INVENTARIOSDataGridView.Focus()
    '    Catch ex As Exception
    '        MessageBox.Show(ex.Message)
    '        lbGlobalcom.cError.SalvaError(ex, "Henry")
    '    End Try
    'End Sub




    'Private Sub btnBuscaBodega_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
    '    Try
    '        Dim flBod As New fListaBodegas
    '        If flBod.ShowDialog = Windows.Forms.DialogResult.OK Then
    '            txtBodega.Text = flBod.Bodega
    '            'lbDescripcionBodega.Text = flBod.pDescrip
    '        End If
    '    Catch ex As Exception
    '        MessageBox.Show(ex.Message)
    '        lbGlobalcom.cError.SalvaError(ex, "Henry")
    '    End Try
    'End Sub

    'Private Sub INV_INVENTARIOSDataGridView_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles INV_INVENTARIOSDataGridView.GotFocus
    '    Try
    '        If INV_INVENTARIOSDataGridView.Rows() Then
    '            'INV_INVENTARIOSBindingSource.EndEdit()
    '        End If
    '    Catch ex As Exception
    '        MessageBox.Show(ex.Message)
    '    End Try
    'End Sub

    'Private Sub INV_INVENTARIOSDataGridView_RowEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs)
    '    Try
    '        If e.RowIndex >= 0 AndAlso INV_INVENTARIOSDataGridView.Rows(e.RowIndex).Cells(0).Value IsNot Nothing AndAlso INV_INVENTARIOSDataGridView.Rows(e.RowIndex).Cells(1).Value IsNot Nothing Then
    '            Dim cInvDatalle As New cConsultaSaldoDetalle(DsInventarios, INV_INVENTARIOSDataGridView.Rows(e.RowIndex).Cells(0).Value, INV_INVENTARIOSDataGridView.Rows(e.RowIndex).Cells(1).Value)
    '            DsInventarios.INV_DETALLEINVENTARIOS.Rows.Clear()
    '            cInvDatalle.ConsultaSaldosDetalle()
    '            Dim cinv As New cConsultaSaldoDetalle()
    '            Dim cProd As New cProducto(INV_INVENTARIOSDataGridView.Rows(e.RowIndex).Cells(1).Value)
    '            stMovimi.Text = "Producto: " & cProd.Descripcion() & " - " & "Saldo: " & cinv.calculoSaldo(INV_INVENTARIOSDataGridView.Rows(e.RowIndex).Cells(4).Value, INV_INVENTARIOSDataGridView.Rows(e.RowIndex).Cells(7).Value, INV_INVENTARIOSDataGridView.Rows(e.RowIndex).Cells(6).Value, INV_INVENTARIOSDataGridView.Rows(e.RowIndex).Cells(8).Value, INV_INVENTARIOSDataGridView.Rows(e.RowIndex).Cells(10).Value)
    '        Else
    '            DsInventarios.INV_DETALLEINVENTARIOS.Rows.Clear()
    '        End If
    '    Catch ex As Exception
    '        MessageBox.Show(ex.Message)
    '        lbGlobalcom.cError.SalvaError(ex, "Henry")
    '    End Try
    'End Sub

    Private Sub INV_INVENTARIOSDataGridView_RowEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles INV_INVENTARIOSDataGridView.RowEnter
        Try
            If e.RowIndex >= 0 AndAlso INV_INVENTARIOSDataGridView.Rows(e.RowIndex).Cells(0).Value IsNot Nothing AndAlso INV_INVENTARIOSDataGridView.Rows(e.RowIndex).Cells(1).Value IsNot Nothing Then
                Dim cInvDatalle As New cConsultaSaldoDetalle(DsInventarios, INV_INVENTARIOSDataGridView.Rows(e.RowIndex).Cells(0).Value, INV_INVENTARIOSDataGridView.Rows(e.RowIndex).Cells(1).Value)
                DsInventarios.INV_DETALLE.Rows.Clear()
                cInvDatalle.ConsultaSaldosDetalle()
                Dim cinv As New cConsultaSaldoDetalle()
                Dim cProd As New cProducto(INV_INVENTARIOSDataGridView.Rows(e.RowIndex).Cells(1).Value)
                daPrepack = New lbGlobalcom.dsConsultasGlobalTableAdapters.GLO_LISTAPREPACKTableAdapter
                daPrepack.FillIdProducto(DsConsultasGlobal.GLO_LISTAPREPACK, INV_INVENTARIOSDataGridView.Rows(e.RowIndex).Cells(1).Value)
                stMovimi.Text = "Producto: " & cProd.Descripcion() & " - " & "Saldo: " & cinv.calculoSaldo(INV_INVENTARIOSDataGridView.Rows(e.RowIndex).Cells(4).Value, INV_INVENTARIOSDataGridView.Rows(e.RowIndex).Cells(7).Value, INV_INVENTARIOSDataGridView.Rows(e.RowIndex).Cells(6).Value, INV_INVENTARIOSDataGridView.Rows(e.RowIndex).Cells(8).Value, cGeneral.NZ(INV_INVENTARIOSDataGridView.Rows(e.RowIndex).Cells(10).Value))
                Dim DetMov As cConsultaDetalleMovimiento = New cConsultaDetalleMovimiento(INV_INVENTARIOSDataGridView.Rows(e.RowIndex).Cells("IDPRODUCTO").Value, INV_INVENTARIOSDataGridView.Rows(e.RowIndex).Cells("IDBODEGA").Value, DsConsultaInv, INV_INVENTARIOSDataGridView.Rows(e.RowIndex).Cells("PERIODO").Value)
                DetMov = Nothing
            Else
                DsInventarios.INV_DETALLEINVENTARIOS.Rows.Clear()
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Henry")
        End Try
    End Sub

    Private Sub btnBuscaProducto_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnBuscaProducto.Click
        Try
            Dim flPro As New fListaProductos
            If flPro.ShowDialog = Windows.Forms.DialogResult.OK Then
                txtProducto.Text = flPro.idArticulo
                'lbDescripcionProducto.Text = flPro.pDescrip
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Henry")
        End Try
    End Sub

    Private Sub btnBuscaBodega_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnBuscaBodega.Click
        Try
            Dim flBod As New fListaBodegas
            If flBod.ShowDialog = Windows.Forms.DialogResult.OK Then
                txtBodega.Text = flBod.Bodega
                'lbDescripcionBodega.Text = flBod.pDescrip
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Henry")
        End Try
    End Sub

    'Private Sub btnCancelar_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancelar.Click
    '    Me.DialogResult = Windows.Forms.DialogResult.Cancel
    'End Sub

    Private Sub btnConsultar_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnConsultar.Click
        Try
            DsInventarios.INV_DETALLEINVENTARIOS.Rows.Clear()
            DsInventarios.INV_INVENTARIOS.Rows.Clear()
            DsInventarios.INV_DETALLE.Rows.Clear()
            DsConsultasGlobal.GLO_LISTAPREPACK.Rows.Clear()
            Dim cInv As New cConsultaSaldosInventario(DsInventarios, Me.txtProducto.Text, Me.txtBodega.Text, cbPeriodo.SelectedValue, cbTipoSubProd.SelectedValue, txtNumeroReg.Text)
            cInv.consultarSaldo()
            INV_INVENTARIOSDataGridView.Focus()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Henry")
        End Try

    End Sub

    Private Sub btnCancelar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.DialogResult = Windows.Forms.DialogResult.Cancel
    End Sub

    
    Private Sub fSaldosProductos_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            Dim daPeri As New lbGlobalcom.dsGlobalTableAdapters.GLO_PERIODOSTableAdapter
            daPeri.Fill(DsGlobal.GLO_PERIODOS)
            Dim Per As cPeriodos = New cPeriodos()
            cbPeriodo.SelectedValue = Per.IDPERIODO
            Per = Nothing
            If CustomPrincipal.IsInRole("ADMINGC") Then
                cbPeriodo.Enabled = True
            Else
                cbPeriodo.Enabled = False
            End If
            Dim daTipoSp As New lbGlobalcom.dsGlobalTableAdapters.GLO_DATOSTABLASTableAdapter
            daTipoSp.FillByIdGrupo(DsGlobal.GLO_DATOSTABLAS, "sp")
            cbTipoSubProd.SelectedValue = 3
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Henry")
        End Try
    End Sub

  
End Class